package crp.core.security.domain.repositories;

import crp.core.security.domain.models.UserBasicCredentialEntity;
import crp.core.security.domain.models.UserBasicPrincipalType;
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase;
import io.quarkus.panache.common.Parameters;

import javax.enterprise.context.ApplicationScoped;
import java.util.Optional;

@ApplicationScoped
public class UserBasicCredentialRepository implements PanacheRepositoryBase<UserBasicCredentialEntity, String> {

    public Optional<UserBasicCredentialEntity> findBy(UserBasicPrincipalType principalType,
                                                      String principal) {
        return find("principalType = :principalType and principal = :principal",
                Parameters.with("principalType", principalType)
                        .and("principal", principal)).firstResultOptional();
    }
}
